//
//  UIView+DimView.m
//  KYVideoModule
//
//  Created by leoking870 on 2017/9/27.
//

#import "UIView+DimView.h"
#define DIMVIEW_TAG 3000000
@implementation UIView (DimView)

- (UIView *)addViewAsDimBackgroundForView:(UIView *)view {
    UIView* grayBackgroundView = [[UIView alloc]initWithFrame:self.bounds];
    grayBackgroundView.backgroundColor = [UIColor blackColor];
    grayBackgroundView.alpha = 0.0f;
    grayBackgroundView.tag = (NSInteger)view;
    [self addSubview:grayBackgroundView];
    [grayBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    return grayBackgroundView;
}

- (void)setDimViewAlpha:(CGFloat)alpha forView:(UIView*)view{
    UIView* grayBackgroundView = [self viewWithTag:(NSInteger)view];
    grayBackgroundView.alpha = alpha;
}

- (void)removeDimViewForView:(UIView *)view {
    UIView* grayBackgroundView = [self viewWithTag:(NSInteger)view];
    [grayBackgroundView removeFromSuperview];
}

- (UIView *)addViewAsTransparentBackgroundForView:(UIView *)view {
    UIView *dimView = [self addViewAsDimBackgroundForView:view];
    dimView.backgroundColor = [UIColor clearColor];
    dimView.alpha = 1.0;
    return dimView;
}

@end
